<template>
	<view class="page">
		<view class="evaluate-goods">
			<view class="list" v-for="(item,index) in dataInfo.order" :key="index">
				<view class="picture">
					<image :src="item.goods_cover"></image>
				</view>
				<view class="item">
					<view class="title">
						<text>{{item.goods_name}}</text>
					</view>
					<view class="star-list">
						<view class="hint">
							<text>{{item.goods_spec}}</text>
						</view>
						
					</view>
					<view class="price">
						<text style="margin-right: 10rpx;">￥{{item.price_selling}}</text>
						<text>x{{item.stock_sales}}</text>
					</view>
				</view>
			</view>
		</view>
		<!--填写-->
		<view class="input-info">
			<view class="dianping">
				<view class="taidu">
					<view style="width: 120px;">商品评价</view>
					<view>
						<tui-rate :current="index" :hollow="true" @change="change" active='#fe3b0f'></tui-rate>
					</view>
				</view>
			</view>
			<!-- <view class="input-title">
				<text>分享你的使用体验吧</text>
			</view> -->
			<view class="input-text">
				<textarea placeholder="感觉怎么？跟大家分享一下吧~" v-model="content"></textarea>
				<view class="record-text">
					<text>已写</text>
					<text class="ac">12</text>
					<text>个字</text>
				</view>
			</view>
			<view class="anonymous">
				<radio class="radio" :checked="isChecked" color="red" style="transform:scale(0.7)" @click="getNi"></radio>
				<text>匿名评价</text>
			</view>
		</view>
		<!--上传图片-->
		<view class="upload-img">
			<view class="img-title">
				<text>上传图片/视频</text>
			</view>
			<view class="img-list">
				<view class="list up-img" @click="unpload">
					<image src="/static/up_img.png"></image>
				</view>
				<view class="list" v-for="(item,index) in imgs" :key="index">
					<image :src="item"></image>
					<text class="iconfont icon-close1" @click="close(index)"></text>
				</view>
				
			</view>
		</view>
		<!--提交-->
		<view class="submit-btn">
			<view class="btn">
				<text @click="submite">提交</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isChecked: false,
				order_no: '',
				dataInfo: '',
				index:0,
				content:'',
				imgs:[]
			};
		},
		onLoad(e) {
			this.dataInfo = JSON.parse(e.item)
			console.log(this.dataInfo)
		},
		methods: {
			change: function(e) {
				this.index = e.index;
			},
			getNi(){
				this.isChecked =!this.isChecked
			},
			submite(){
				let that = this
				let images = ''
				that.imgs.map((item,index)=>{
					images = images+item+'|'
				})
				images = images.slice(0, -1)
				that.tui.request('api.auth.order/orderComment', "post", {order_no:that.dataInfo.order_no,rating:that.index,content:that.content,is_anony:that.isChecked?'1':'2',img:images}, false, true, false).then((res) => {
					console.log(res)
					that.tui.toast(res.info)
					if(res.code==1){
						setTimeout(function(){
							uni.navigateBack()
						},500)
					}
					
				}).catch((res) => {
					console.log(res)
				})
			},
			unpload(e){
				console.log(e)
				let that = this
				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'],
					sourceType: ['album', 'camera'],
					success: res => {
						// that.headerimg = res.tempFilePaths[0];
						let tempFilePaths = res.tempFilePaths[0];
						that.tui.uploadFile("api.data/upload",tempFilePaths).then((res) => {
							if(res.code==1){
								that.imgs.push(res.data.url)
							}
						}).catch((res) => {})
					}
				});
				
			},
			close(e){
				this.imgs.splice(e, 1)
				console.log(this.imgs)
			},
		}
	}
</script>

<style scoped lang="scss">
	@import "MyEvaluatePush.scss";
</style>
